package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.itheima.aspact.RecordTimeAnno;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.*;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public PageResult page(StudentQueryParam param) {
//        Page<Student> page = new Page<>(param.getPage(),param.getPageSize());
//        LambdaQueryWrapper<Student> wrapper = new LambdaQueryWrapper<>();
//            page = studentMapper.page(page,wrapper);

//        PageHelper.startPage(studentQueryParam.getPage(),studentQueryParam.getPageSize());
//
//        List<Student> studentList =studentMapper.list(studentQueryParam);
//
//        Page<Student> page = (Page<Student>) studentList;
//
//        return new PageResult(page.getTotal(),page.getResult());
        return null;
    }
    @RecordTimeAnno
    @Override
    public void deleteByIds(List<Integer> ids) {
            studentMapper.delete(ids);
    }

    @Override
    public Student getInfo(Integer id) {
        return studentMapper.getById(id);
    }
    @RecordTimeAnno
    @Override
    public void update(Student student) {
        student.setUpdateTime(LocalDateTime.now());

        studentMapper.updateById(student);
    }
    @RecordTimeAnno
    @Override
    public void save(Student student) {
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.save(student);
    }
    @RecordTimeAnno
    @Override
    public void update(Integer id, Integer score) {
        studentMapper.update(id,score);
    }


    @Override
    public List<Map> getStudentDegreeData() {
        return   studentMapper.getStudentDegreeData();
    }

    @Override
    public JobOption1 getStudentCountData() {
        List<Map<Object,Object>> map = studentMapper.getStudentCountData();
        List clazzList = new ArrayList();
        List dataList = new ArrayList();
        for (Map<Object, Object> map1 : map) {
            clazzList.add(map1.get("clazzList"));
            dataList.add(map1.get("dataList"));
        }
        return new JobOption1(clazzList,dataList);
    }
}
